package com.xxx.protobuf.client;

import com.xxx.protobuf.MessageProto;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * protobuf： client端handler
 */
public class ProtobufClientHandler extends SimpleChannelInboundHandler<MessageProto.Response> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MessageProto.Response response) {
        System.out.println("Received response from server:");
        System.out.println("Total pages: " + response.getTotalPages());
        for (String result : response.getResultList()) {
            System.out.println("Result: " + result);
        }
        ctx.close();
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }
}